package Multithreading.Exercise006;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * ClassName:ThreadDome
 * Package:Multithreading.Exercise006
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/6-23:06
 * @Version:v1.0
 */
public class ThreadDome {
    /*同时开启两个线程,共同获取1-100之间的所有数字
    * 要求：将输出所有奇数*/
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable mc=new MyCallable();
        FutureTask<ArrayList<String>> ft = new FutureTask<>(mc);
        Thread t1 = new Thread(ft);
        Thread t2 = new Thread(ft);
        t1.setName("线程A-");
        t2.setName("线程B-");
        t1.start();
        t2.start();
        ArrayList<String> list = ft.get();
        for (String s : list) {
            System.out.println(s);
        }
    }
}
